package org.zcl.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.zcl.dao.ActivityDao;
import org.zcl.dao.TbUserInfoDao;
import org.zcl.entity.po.Activity;
import org.zcl.entity.po.TbUserInfo;
import org.zcl.service.ActivityService;

import java.util.List;

/**
 * 活动(Activity)表服务实现类
 *
 * @author Chenglin Zhu
 * @since 2022-01-28 14:08:49
 */
@Service("activityService")
@Slf4j
public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> implements ActivityService {

    @Autowired
    private TbUserInfoDao tbUserInfoDao;

    @Autowired
    private ActivityDao activityDao;

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public void updateName(TbUserInfo userInfo) {
        try {
            Thread.sleep(1000);
            log.info("事务2执行更新，userInfo:{}", JSON.toJSONString(userInfo));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        tbUserInfoDao.updateById(userInfo);
    }

    @Override
    public Boolean batchUpsert(List<Activity> activities) {
        activityDao.batchUpsert(activities);
        return true;
    }
}

